package com.data.unityplugin_market.viewmodel

import android.app.Activity
import android.content.Context
import android.databinding.ObservableField
import android.support.v4.app.FragmentActivity
import com.data.unityplugin_market.base.BaseFragment
import com.data.unityplugin_market.base.BaseVM
import com.data.unityplugin_market.business.center.AddressFragment
import com.data.unityplugin_market.business.center.CustomerFragment
import com.data.unityplugin_market.business.center.MyOrderFragment
import com.data.unityplugin_market.business.center.SystemSettingFragment
import com.data.unityplugin_market_lib.R

public class PersonalActVM : BaseVM {

    var act: FragmentActivity? = null;

    var fragments = ArrayList<BaseFragment>()

    /**
     *
     */
    var myOrderClick = ObservableField<Boolean>(true)

    /**
     * 地址点击
     */
    var addressClick = ObservableField<Boolean>()

    /**
     *
     */
    var customerCenterClick = ObservableField<Boolean>()

    /**
     * 系统设置点击
     */
    var systemSettingClick = ObservableField<Boolean>()


    constructor(context: Context) {
        act = context as FragmentActivity
        fragments.add(MyOrderFragment())
        fragments.add(AddressFragment())
        fragments.add(CustomerFragment())
        fragments.add(SystemSettingFragment())

    }


    fun myOrderFragment() {
        myOrderClick.set(true)
        addressClick.set(false)
        customerCenterClick.set(false)
        systemSettingClick.set(false)

        act!!.supportFragmentManager.beginTransaction().replace(R.id.container, fragments[0]).commit()
    }

    fun addressFragment() {
        myOrderClick.set(false)
        addressClick.set(true)
        customerCenterClick.set(false)
        systemSettingClick.set(false)
        act!!.supportFragmentManager.beginTransaction().replace(R.id.container, fragments[1]).commit()
    }

    fun customerFragment() {
        myOrderClick.set(false)
        addressClick.set(false)
        customerCenterClick.set(true)
        systemSettingClick.set(false)
        act!!.supportFragmentManager.beginTransaction().replace(R.id.container, fragments[2]).commit()
    }

    fun systemSettingFragment() {
        myOrderClick.set(false)
        addressClick.set(false)
        customerCenterClick.set(false)
        systemSettingClick.set(true)
        act!!.supportFragmentManager.beginTransaction().replace(R.id.container, fragments[3]).commit()
    }

    fun back(){
        act!!.finish()
    }

    var context: Context? = null


    var text = ObservableField<String>();
}
